home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 December / PCWDEC06.iso / Software / Trial / Paint Shop Pro XI / Data1.cab / _A0F4DC3D6290486594D95861D48DA489 < prev    next >
Encoding:
Text File  |  2006-08-04  |  5.3 KB  |  115 lines

  1. from PSPApp import *
  2. import PSPUtils
  3.  
  4. def ScriptProperties():
  5.     return {
  6.         'Author': 'Linda Nieuwenstein',
  7.         'Copyright': u'Copyright (c) 2002-2006 Corel Corporation. All rights reserved.',
  8.         'Description': "Split the current image to HSL, putting the separate channels back as layers in a layer group.",
  9.         'Host': 'Paint Shop Pro',
  10.         'Host Version': '8.00'
  11.         }
  12.  
  13.  
  14. def Do(Environment):
  15.     if PSPUtils.RequireADoc( Environment ) == App.Constants.Boolean.false:
  16.         return
  17.     
  18.     # keep track of the doc we are starting with
  19.     TargetDoc = App.TargetDocument
  20.     
  21.     # start by splitting the current image.
  22.     App.Do( Environment, 'SplitToHSL', {
  23.             'GeneralSettings': {
  24.                 'ExecutionMode': App.Constants.ExecutionMode.Default, 
  25.                 'AutoActionMode': App.Constants.AutoActionMode.Match
  26.                 }
  27.             })
  28.  
  29.     # the split created 3 new documents and puts them at the end of the open list.
  30.     # make a three element list that we can reorder.  At this point we don't
  31.     # care about the contents, just that it has three elements
  32.     NewDocs = App.Documents[-3:]                # grab the last three docs
  33.           
  34.     # now loop over the three newest docs.
  35.     for ChannelDoc in App.Documents[-3:]:
  36.         Name = ChannelDoc.Title
  37.         if Name.find( PSPUtils.Lightness ) != -1:
  38.           NewDocs[0] = ChannelDoc # make Lightness first
  39.         elif Name.find( PSPUtils.Saturation ) != -1:
  40.           NewDocs[1] = ChannelDoc # make Saturation next
  41.         elif Name.find( PSPUtils.Hue ) != -1:
  42.           NewDocs[2] = ChannelDoc # make Hue last
  43.             
  44.     FirstChannel = App.Constants.Boolean.true   # need special handling on the first one
  45.     
  46.     # We use explicit specification of which document to work on by adding a fourth
  47.     # parameter to the App.Do call.  For operations on one of the single channel
  48.     # images we use one of the saved docs.  For operations on the original doc we use
  49.     # the saved TargetDoc.
  50.     for Doc in NewDocs:  
  51.         # this shouldn't be necessary, but at the moment paste as new layer has a bug,
  52.         # so we promote manually.  This assumes the original image is RGB.
  53.         App.Do( Environment, 'IncreaseColorsTo16Million', {}, Doc )
  54.         
  55.         # copy it to the clipboard        
  56.         App.Do( Environment, 'Copy', {}, Doc  )
  57.         
  58.         # paste it into the existing document - note the specification of target doc
  59.         App.Do( Environment, 'PasteAsNewLayer', {}, TargetDoc )
  60.  
  61.         # when we pasted it the layer came in as Raster Layer n, and we want to know what
  62.         # channel it represents, so pick up the image title and use that to determine
  63.         # the layer name.  Out of split to HSL the image will be named HueN, SaturationN, and LightnessN.
  64.         NewLayerName = Doc.Title
  65.         if NewLayerName.find( PSPUtils.Lightness ) != -1:
  66.             NewLayerName = PSPUtils.LightnessChannel
  67.         elif NewLayerName.find( PSPUtils.Saturation ) != -1:
  68.             NewLayerName = PSPUtils.SaturationChannel
  69.         else:
  70.             NewLayerName = PSPUtils.HueChannel
  71.             
  72.         # now that we have the layer name, rename it
  73.         App.Do( Environment, 'LayerProperties', {
  74.                 'General': {
  75.                     'Name': NewLayerName, 
  76.                     }, 
  77.                 'GeneralSettings': {
  78.                     'ExecutionMode': App.Constants.ExecutionMode.Silent, 
  79.                     'AutoActionMode': App.Constants.AutoActionMode.Default
  80.                     }
  81.                 }, TargetDoc )
  82.         
  83.         # we want the channels to end up inside of a layer group, so after we
  84.         # paste the first channel in create a layer group to hold it, and then select
  85.         # the layer inside the group so subsequent creates go where we want them.
  86.         if FirstChannel == App.Constants.Boolean.true:
  87.             FirstChannel = App.Constants.Boolean.false
  88.  
  89.             # create the layer group
  90.             App.Do( Environment, 'NewLayerGroup', {
  91.                     'General': {
  92.                         'Name': PSPUtils.HSLChannels, 
  93.                         }, 
  94.                     'GeneralSettings': {
  95.                         'ExecutionMode': App.Constants.ExecutionMode.Silent, 
  96.                         'AutoActionMode': App.Constants.AutoActionMode.Match
  97.                         }
  98.                     }, TargetDoc )
  99.  
  100.             # select the member of the group rather than the group itself            
  101.             NewLayer = App.Do( Environment, 'SelectLayer', {
  102.                     'Path': (0,0,[1],App.Constants.Boolean.false), 
  103.                     'GeneralSettings': {
  104.                         'ExecutionMode': App.Constants.ExecutionMode.Silent, 
  105.                         'AutoActionMode': App.Constants.AutoActionMode.Default
  106.                         }
  107.                     }, TargetDoc)
  108.             
  109.         # do the close in silent mode since we don't want to save changes                
  110.         App.Do( Environment, 'FileClose', {
  111.                 'GeneralSettings': {
  112.                     'ExecutionMode': App.Constants.ExecutionMode.Silent, 
  113.                     'AutoActionMode': App.Constants.AutoActionMode.Match
  114.                     }
  115.                 }, Doc )